package Process;

import java.util.*;

/**
 * This abstract class represents a generic process
 * and the various fields and methods a process
 * would require.
 * 
 * @author Stephen Amos, Zach Turk, Dickson Kwong
 *
 */
public abstract class Process extends Observable
{
	/**
	 * The identifier of this process.
	 */
	protected int process_id;
	
	/**
	 * The number of requests for this process.
	 * 
	 */
	protected int number_of_requests;	
	
	/**
	 * The list of requests this particular process has.
	 */
	protected  SysCall[] requests;
	
	/**
	 * Request program counter.
	 */
	protected int request_counter = 0;
	
	/**
	 * Constructor that doesn't require the counter.
	 * @param the_id
	 * @param the_requests
	 */
	public Process(int the_id, SysCall[] the_requests) {
		this(the_id, the_requests, 0);
	}
	
	/**
	 * Constructs a process based upon the following parameters
	 * (In the order they are specified in the constructor):
	 * Process ID, The current number of steps of this process,
	 * and the current number of requests for this process.
	 * 
	 * @param the_id The process ID
	 * @param the_steps The current number of steps
	 * @param the_requests The current number of requests
	 */
	public Process(int the_id, SysCall[] the_requests, int the_counter)
	{
		process_id = the_id;
		requests = the_requests;
		request_counter = the_counter;
		
		for (int i = 0; i < requests.length; i++) {
			requests[i] = SysCall.IDLE;
		}
	}
	
	/**
	 * Returns the identifier of this process.
	 */
	public int getProcessID()
	{
		return process_id;
	}
	
	/**
	 * Returns the number of requests this process is currently at.
	 */
	public int getNumberOfRequests()
	{
		return number_of_requests;
	}
	
	/**
	 * Returns the process request and updates the program counter
	 * of this process to the next request.
	 */
	public SysCall next()
	{
		SysCall request_to_return = requests[request_counter];
		request_counter++;
		request_counter %= requests.length;
		return request_to_return;
	}
	
	/**
	 * An enum class for the system calls.
	 * @author Dickson Kwong, Stephen Amos, Zach Turk
	 */
	public enum SysCall 
	{
		 IDLE, KEYBOARD_IO, VIDEO_IO, DISK_IO, SEM_DOWN, SEM_UP, MEM_WRITE, MEM_READ, MUTEX_LOCK, MUTEX_UNLOCK;
	}
}